package com.lightjet.macross.base.log.repository;

import com.lightjet.macross.base.log.domain.LogIndex;
import com.lightjet.macross.common.core.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import sun.rmi.runtime.Log;

import java.util.Date;

@Repository("logIndexRepository")
public interface LogIndexRepository extends BaseRepository<LogIndex, Integer> {

    @Query("select t from LogIndex t  where coalesce(t.caption,'!@#$')  like :caption " +
            "and coalesce(t.apiuri,'!@#$') like :apirui " +
            "and coalesce(t.servicename,'!@#$') like :servicename " +
            "and coalesce(t.clientid,'!@#$') like :clientid " +
            "and (t.loglevel = :loglevel or :loglevel = -1) " +
            "and (t.result = :result or :result = -1) " +
            "and t.createDate between :sdate and :edate")
    Page<LogIndex> findByFilters(
            @Param("caption") String caption,
            @Param("servicename") String servicename,
            @Param("apirui") String apirui,
            @Param("clientid") String clientid,
            @Param("loglevel") byte loglevel,
            @Param("result") byte result,
            @Param("sdate") Date sdate,
            @Param("edate") Date edate,
            Pageable pageable
    );

}
